import { _decorator, Component, Node, v3 } from 'cc';
import { GlobalConfig } from '../../../Init/Config/GlobalConfig';
import GlobalPool from '../../../Init/Tools/GlobalPool';
const { ccclass, property } = _decorator;

@ccclass('MappingObj')
export class MappingObj {
    node: Node = null;
    /**2d属性 */
    mappingProps: { node: Node, state?: number, data?, type?} = null;
    //3d缩放
    s3d = GlobalConfig.Scale2DTo3D;
    //--临时变量
    tmpP = v3();
    tmpR = v3();
    tmpS = v3();

    constructor(node: Node, mp?: { node: Node, state?: number, data?, type?}) {
        this.node = node;
        this.mappingProps = mp;
    }

    init(d?) {
        this.updateProp();
    }

    reset() {

    }

    updateProp() {
        //回收
        if (!this.mappingProps.node.active) {
            GlobalPool.put(this.node);
            return;
        }

        //位置
        this.tmpP.set(this.mappingProps.node.position);
        this.tmpP.z = -this.tmpP.y;
        this.tmpP.y = 0;
        this.node.setPosition(this.tmpP.multiplyScalar(this.s3d));
        //旋转
        this.tmpR.x = 0;
        this.tmpR.z = 0;
        if (Math.abs(this.mappingProps.node.eulerAngles.x) == 180) {
            this.tmpR.y = -(this.mappingProps.node.eulerAngles.z % 360) + 180;
        } else {
            this.tmpR.y = this.mappingProps.node.eulerAngles.z;
        }
        this.node.eulerAngles = this.tmpR;

    }

    update(dt) {
        this.updateProp();
    }
}

